package net.oschina.app.testcases.favorites;

import android.util.Log;
import android.view.View;
import android.widget.EditText;

import com.robotium.solo.By;
import com.robotium.solo.Solo;
import com.robotium.solo.WebElement;

/**
 * Created by Administrator on 2017/7/1.
 */

public class SoloWrap {
    private Solo solo;

    //构造方法SoloWrap  有个参数Solo
    public SoloWrap(Solo solo) {
        //把 外界的solo 传给我 自己的solo
        this.solo = solo;
    }

    //封装 （点击）
    public void clickOnView(View view) {
        Log.i("AUTO", "click on view :" + view.getId());
//        solo.waitForView(view, 1, 5000);
        solo.clickOnView(view);
    }

    //封装 用id定位
    public View getView(String id) {
        try {
            return solo.getView(id);
        } catch (Throwable th) {
            return null;
        }
    }

    //封装 输入文本
    public void enterText(EditText et, String text) {
        solo.enterText(et, text);
    }

    //封装 清空
    public void clearEditText(EditText et) {
        solo.clearEditText(et);
    }

    public boolean searchText(String text) {
        return solo.searchText(text, true);
    }

    public void sleep(int seconds) {
        solo.sleep(1000 * seconds);
    }

    public boolean waitForText(String text, int seconds) {
        return solo.waitForText(text, 1, seconds * 1000);
    }

    public void takeScreenShot(String name) {
        solo.takeScreenshot(name);
    }

    public void clickInList(int row) {
        solo.clickInList(row);
    }

    public void waitForView(View view) {
        solo.getView(view);
    }

    public WebElement getWebElementByXpath(String xpath) {
        return solo.getWebElement(By.xpath(xpath), 0);
    }

    public String getWebElementText(WebElement we) {
        return we.getText().toString();
    }

    public void clickListItem(int row) {
        solo.clickInList(row);
    }
}
